<template>
	<view class="gt-form-switch row">
		<view class="gt-form-label row">
			<view class="col-auto"></view>
			<text>{{label}}</text>
			<uni-icons v-if="desc" class="gt-form-label-desc" type="help" size="20" color="#999999" @click="showDesc()">
			</uni-icons>
		</view>
		<view class="row flex-center">
			<switch :checked="value === successValue ? true : false"  @change="changeSwitch" style="transform:scale(0.7)" ></switch>
		</view>
		
	</view>
</template>

<script>
	export default {
		name: "switch",
		model: {
			prop: 'value',
			event: 'change'
		},
		props: {
			value: {
				type: [Number, String,Boolean],
				default: ''
			},
			label: {
				type: String,
				default: ''
			},
			desc: {
				type: String,
				default: ''
			},
			field: {
				type: String,
				default: ''
			},
			successValue: {
				type: [Number, String,Boolean],
				default: true
			},
			failValue:{
				type: [Number, String,Boolean],
				default: false
			}
		},
		created() {},
		data() {
			return {
				name: ''
			}
		},
		computed: {},
		methods: {
			changeSwitch(e){
				let value = e.detail.value ? this.successValue : this.failValue;
				this.$emit('change',value,this.field);
				
			},
			showDesc() {
				uni.showModal({
					title: this.label,
					content: this.desc,
					showCancel: false
				})
			}
		}
	}
</script>

<style lang="scss">
	.gt-form-label {
		width: 120px;
		line-height: 38px;
		margin-right: 15px;
	}
</style>
